package com.gitee.kamismile.stone.basic.data.infrastructure.repository.r2Repository.sysdic.persistence;

import com.gitee.kamismile.stone.basic.data.domain.sysdic.aggregate.enums.StateEnum;
import com.gitee.kamismile.stone.basic.data.domain.sysdic.repository.entity.SysDictionary;
import com.gitee.kamismile.stone.basic.data.domain.sysdic.repository.persistence.ISysDictionaryPersistence;
import com.gitee.kamismile.stone.basic.data.infrastructure.repository.r2Repository.sysdic.repository.SysDictionaryRepository;
import com.gitee.kamismile.stone.basic.data.infrastructure.utils.PageQueryBuilder;
import com.gitee.kamismile.stone.basic.data.infrastructure.utils.QueryBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
import org.springframework.data.relational.core.query.Criteria;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

import java.util.Objects;

@Service
public class SysDictionaryPersistenceImpl implements ISysDictionaryPersistence {

    @Autowired
    private SysDictionaryRepository sysDictionaryRepository;

    @Autowired
    private R2dbcEntityTemplate r2dbcEntityTemplate;

    @Override
    public Mono<SysDictionary> findOne(Criteria criteria) {
        return new QueryBuilder<>(r2dbcEntityTemplate, SysDictionary.class)
                .where(criteria)
                .apply().one();
    }

    @Override
    public Mono<SysDictionary> save(SysDictionary entity) {
            return  sysDictionaryRepository.save(entity);
    }

    @Override
    public Mono<Void> deleteDicById(Integer nSysDictionaryId,Integer nTenantId){
//        SysDictionary sysDictionary=new SysDictionary();
//        sysDictionary.setnSysDictionaryId(nSysDictionaryId);
//        sysDictionary.setnState(StateEnum.Delete.getCode());
        return sysDictionaryRepository.deleteById(Long.valueOf(nSysDictionaryId));
    }
}
